home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / othergnu / gnuplot.zoo / atari.trm < prev    next >
Text File  |  1992-03-01  |  7KB  |  284 lines

  1. /* GNUPLOT - atari.trm */
  2. /*
  3.  * Copyright (C) 1991
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed
  13.  * as patches to released version.
  14.  *
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  *
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *   Atari Screens working with the normal VDI
  21.  *     (this should include TT and big screens)
  22.  *
  23.  * AUTHORS
  24.  *  Alexander Lehmann
  25.  *  02/13/92           Derived from an unreleased version for GP 2.02
  26.  *
  27.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  28.  *
  29.  * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
  30.  * (up to know this is not in the official GP release)
  31.  *
  32.  */
  33.  
  34. #include <aesbind.h>
  35. #include <vdibind.h>
  36. #include <osbind.h>
  37.  
  38. /* default to hi-res */
  39.  
  40. #define ATARI_XMAX 640
  41. #define ATARI_YMAX 400
  42. #define ATARI_VCHAR 16
  43. #define ATARI_HCHAR 8
  44. #define ATARI_HTIC (ATARI_XMAX/80)
  45. #define ATARI_VTIC (ATARI_YMAX/80)
  46.  
  47. #define ATARI_yc(y) (ATARI_maxycoord-y)
  48.  
  49. static int vdi_handle=-1;
  50. static int ATARI_maxycoord;
  51. static int ATARI_lt;
  52. static int ATARI_rotation;
  53. static int ATARI_numcolors;
  54. static int pxy[128];            /* Maximum of 64 pixels per v_pline */
  55. static int pxy_index;
  56. static int ATARI_colors[16];
  57. static int ATARI_savecolors[16][3];
  58. static int ATARI_numpalette;
  59.  
  60. ATARI_options( )
  61. {
  62. #define ATARIERROR "palette values 3 hex digit, please"
  63.     char opt[4];
  64.     int i;
  65.     char *tok_end;
  66.  
  67.     term_options[0]='\0';
  68.  
  69.     for( i=0 ; i<16 ; i++ ) {
  70.         if(END_OF_COMMAND) break;
  71.         if (token[c_token].length>3)
  72.             int_error(ATARIERROR, c_token);
  73.  
  74.         capture( opt, c_token, c_token );
  75.         ATARI_colors[i]=strtoul( opt, &tok_end, 16 );
  76.         if( *tok_end!='\0' )
  77.             int_error(ATARIERROR, c_token);
  78.  
  79.         sprintf( opt, "%03X ", ATARI_colors[i] );
  80.         strcat( term_options, opt );
  81.         c_token++;
  82.     }
  83.  
  84.     ATARI_numpalette=i;
  85. }
  86.  
  87. ATARI_init( )
  88. {
  89.     int work_in[11];
  90.     int work_out[57];
  91.     int i;
  92.     int hchar, wchar, dummy;
  93.     int rgb[3];
  94.     int num_save;
  95.     char *colors,*tok_end;
  96.  
  97.     if( ATARI_numpalette==0 && (colors=getenv("GNUCOLORS")) ) {
  98.         for( i=0 ; i<16 ; i++ ) {
  99.             if( *colors=='\0' ) break;
  100.             ATARI_colors[i]=strtoul( colors, &tok_end, 16 );
  101.             if( colors==tok_end || (unsigned)ATARI_colors[i]>0xfff ) {
  102.                 i=0;
  103.                 break;
  104.             }
  105.             colors=tok_end;
  106.             while( *colors==' ' ) colors++;
  107.         }
  108.         ATARI_numpalette=i;
  109.     }
  110.  
  111.     vdi_handle=graf_handle( &wchar, &hchar, &dummy, &dummy );
  112.  
  113.     for( i=0 ; i<10 ; work_in[i++]=1 );
  114.         work_in[10]=2;                  /* use raster coordinates */
  115.     v_opnvwk( work_in, &vdi_handle, work_out );
  116.     if( !vdi_handle )
  117.         int_error("Fatal error opening virtual workstation", NO_CARET);
  118.  
  119.     term_tbl[term].xmax=work_out[0]+1;
  120.     term_tbl[term].ymax=work_out[1]+1;
  121.     term_tbl[term].h_char=wchar;
  122.     term_tbl[term].v_char=hchar;    /* hchar stands for height this time */
  123.     term_tbl[term].v_tic=(work_out[1]+1)/80;
  124.     term_tbl[term].h_tic=(work_out[0]+1)/80;
  125.  
  126.     ATARI_maxycoord=work_out[1];
  127.     ATARI_numcolors=work_out[13];
  128.     pxy_index=0;
  129.  
  130.     for( i=0 ; i<ATARI_numpalette ; i++ ) {
  131.         vq_color( vdi_handle, i, 1, ATARI_savecolors[i] );
  132.  
  133.         rgb[0]=1000*(ATARI_colors[i]>>8);
  134.         rgb[0]/=15;
  135.         rgb[1]=1000*((ATARI_colors[i]>>4)&15);
  136.         rgb[1]/=15;
  137.         rgb[2]=1000*(ATARI_colors[i]&15);
  138.         rgb[2]/=15;
  139.         vs_color(vdi_handle, i, rgb );
  140.     }
  141. }
  142.  
  143. ATARI_reset( )
  144. {
  145.     int i;
  146.  
  147.     if( vdi_handle!=-1 ) {
  148.         for( i=0 ; i<ATARI_numpalette ; i++ ) {
  149.             vs_color(vdi_handle, i, ATARI_savecolors[i] );
  150.         }
  151.         v_clsvwk( vdi_handle );
  152.         vdi_handle=-1;
  153.     }
  154. }
  155.  
  156. ATARI_graphics( )
  157. {
  158.     fflush( stdout );
  159.     fflush( stderr );
  160.     Cconws( "\033f" ); /* turn cursor off */
  161.     v_clrwk( vdi_handle );
  162.     pxy_index=0;
  163. }
  164.  
  165. flush_line( )
  166. {
  167.     int line_type;
  168.     int color_index;
  169.     int i;
  170.  
  171.     if( pxy_index>=2 ) {
  172.         if( ATARI_lt<0 ) {
  173.             color_index=1;  /* black */
  174.             line_type=0;    /* solid line */
  175.         } else {
  176.             if( ATARI_numcolors==2 ) { /* Monochrome */
  177.                 color_index=1;
  178.                 line_type=ATARI_lt % 4;
  179.             } else { /* Color */
  180.                 color_index=2+ATARI_lt%(ATARI_numcolors-2);
  181.                 line_type=(ATARI_lt/(ATARI_numcolors-2)) % 4;
  182.             }
  183.         }
  184.  
  185.         vswr_mode( vdi_handle, MD_TRANS );
  186.         vsl_color( vdi_handle, color_index );
  187.  
  188.         switch( line_type ) {
  189.             case 0:
  190.                 vsl_type( vdi_handle, 1 );      /* 1111111111111111 */
  191.             break;
  192.             case 1:
  193.                 vsl_type( vdi_handle, 3 );      /* 1110000011100000 */
  194.             break;
  195.             case 2:
  196.                 vsl_type( vdi_handle, 5 );      /* 1111111100000000 */
  197.             break;
  198.             case 3:
  199.                 vsl_type( vdi_handle, 7 );      /* 1010101010101010 */
  200.                 vsl_udsty( vdi_handle, 0xaaaa );
  201.             break;
  202.         }
  203.  
  204.         v_pline( vdi_handle, pxy_index, pxy );
  205.     }
  206.  
  207.     if( pxy_index>=1 ) {
  208.         pxy[0]=pxy[2*(pxy_index-1)];
  209.         pxy[1]=pxy[2*(pxy_index-1)+1];
  210.         pxy_index=1;
  211.     }
  212. }
  213.  
  214. ATARI_text( )
  215. {
  216.     flush_line( );
  217.     Cconws( "\033e" );  /* turn cursor on again */
  218. }
  219.  
  220. ATARI_move( int x, int y )
  221. {
  222.     flush_line( );
  223.  
  224.     pxy_index=1;
  225.     pxy[0]=x;
  226.     pxy[1]=ATARI_yc(y);
  227. }
  228.  
  229. ATARI_vector( int x, int y )
  230. {
  231.     pxy[2*pxy_index]=x;
  232.     pxy[2*pxy_index+1]=ATARI_yc(y);
  233.     pxy_index++;
  234.  
  235.     if( pxy_index==64 ) {   /* we're all full */
  236.         flush_line( );
  237.     }
  238. }
  239.  
  240. ATARI_linetype( int lt )
  241. {
  242.     flush_line( );
  243.  
  244.     ATARI_lt=lt;
  245. }
  246.  
  247. ATARI_put_text( int x, int y, char *str )
  248. {
  249.     struct termentry *t=term_tbl+term;
  250.     int h_char=t->h_char;
  251.     int maxcoord;
  252.     int fixcoord;
  253.     int dummy;
  254.  
  255.     if( !strlen(str) ) return;
  256.  
  257.     /* align text left and to middle of char height */
  258.     vst_alignment( vdi_handle, 0, 1, &dummy, &dummy );
  259.     vst_rotation( vdi_handle, (ATARI_rotation ? 900 : 0) );
  260.     v_gtext( vdi_handle, x, ATARI_yc(y), str );
  261. }
  262.  
  263. BOOLEAN ATARI_text_angle( int ang )
  264. {
  265.     ATARI_rotation=ang;
  266.  
  267.     return TRUE;
  268. }
  269.  
  270. BOOLEAN ATARI_justify_text( int mode )
  271. {
  272.     return FALSE;
  273. }
  274.  
  275. ATARI_point( int x, int y, int number )
  276. {
  277.     if( ATARI_numcolors==2 ) {
  278.         line_and_point( x, y, number ); /* monochrome */
  279.     } else {
  280.         do_point( x, y, number );       /* color, then */
  281.     }
  282. }
  283.  
  284.